//
//  ViewController.m
//  ReactiveCocoaUserDemo
//
//  Created by zsp on 2017/3/14.
//  Copyright © 2017年 zsp. All rights reserved.
//

#import "ViewController.h"
#import <ReactiveCocoa.h>
#import "APIManager.h"
#import "XYUser.h"
#import "XYUserViewModel.h"

@interface ViewController ()

@property(nonatomic, strong)XYUserViewModel *userViewModel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)getUserInfo{
    //第一版：單純使用 AFNetworking
    //    [[APIManager sharedInstance] getUserByEmail:@"test@gmail,com" success:^(XYUser *user) {
    //        //update data
    //        //update UI
    //    } failure:^(NSError *error) {
    //        //data handle error
    //        //UI handle error
    //    }];
    
    //第二版：用 RACSignal 包起來
    [[[APIManager sharedInstance] getUserByEmail:@"test@gmail.com"] subscribeNext:^(XYUser *user) {
        //update data
        //update UI
    } error:^(NSError *error) {
        //data handle error
        //UI handle error
    }];
    
//    第三版：加入 AFNetworking-RACExtensions
    [[[APIManager sharedInstance] getUserByExtEmail:@"test@gmail.com"] subscribeNext:^(XYUser *user) {
        //update data
        //update UI
    } error:^(NSError *error) {
        //data handle error
        //UI handle error
    }];
    
//    第四版：改成 MVVM 模式
    [[self.userViewModel getUserByExtEmail:@"test@gmail.com"] subscribeNext:^(XYUser *user) {
        //update UI
    } error:^(NSError *error) {
        //UI handle error
    }];
}

@end
